package com.bridgeintelligent.tag.webserver.dim.mgmt.service.share;

import com.bridgeintelligent.tag.webserver.dim.mgmt.api.BaseCode;
import com.bridgeintelligent.tag.webserver.dim.mgmt.api.DimRep;
import com.bridgeintelligent.tag.webserver.dim.mgmt.api.model.ShareModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;

/**
 * @description
 * @author: grp 2020-12-29 17:37
 **/
@Api(tags = "标签共享")
@AllArgsConstructor
@RestController
@Validated
@RequestMapping("api/share")
@Slf4j
public class TagShareController {

    private IShareService shareService;
    @ApiOperation(value = "保存共享状态", notes = "共享")
    @PostMapping("/give")
    public DimRep give(@RequestBody  @Valid ShareModel shareModel) {
        try{
            shareService.give(shareModel);
        }catch (Exception e){
            log.error("标签共享保存出错", e);
        }
        return new DimRep(BaseCode.SUCCESS);
    }

    @ApiOperation(value = "查看具体标签详情", notes = "查看共享用户列表")
    @GetMapping("/list/{dimId}")
    public DimRep list(@PathVariable @NotBlank String dimId) {
        return new DimRep(shareService.list(dimId), BaseCode.SUCCESS);
    }
}
